home *** CD-ROM | disk | FTP | other *** search
/ Chip 2003 October / Chip Ekim 2003.iso / prog / code / contr / setup.exe / Disk1 / data1.cab / Configuration_En / Commands / ccAnchor.js < prev    next >
Encoding:
JavaScript  |  2003-07-18  |  2.6 KB  |  89 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved
  2.  
  3. //---------------   GLOBAL VARIABLES   ---------------
  4.  
  5. var helpDoc = MM.HELP_objAnchor;
  6.  
  7.  
  8. //---------------    LOCAL FUNCTIONS   ---------------
  9.  
  10. function initializeUI() 
  11. {
  12.   var curDOM = dw.getDocumentDOM();
  13.   if (curDOM)
  14.   {
  15.     var curSel = dw.getSelection();  //get selection
  16.     if (curSel && curSel.length>1 && curSel[1]>curSel[0]) //if selection exists
  17.     {
  18.       var curText = (curDOM.documentElement.outerHTML.slice(curSel[0],curSel[1]));  //get selection string
  19.       if (curText && curText.search(/[a-zA-Z]\w*/)==0) //if selection starts with word (must begin w/ letter
  20.       {
  21.         var wordArray = curText.match(/[a-zA-Z]\w*/);  //get first word
  22.         document.theform.anchorname.value = unescape(wordArray[0]);  //preload text into UI
  23.       }
  24.     }
  25.   }
  26.  
  27.   document.theform.anchorname.focus();
  28.   document.theform.anchorname.select();
  29. }
  30.  
  31.  
  32. //---------------     API FUNCTIONS    ---------------
  33.  
  34. function canAcceptCommand()
  35. {
  36.   var enabled= dw.getFocus() != 'browser' && dw.getDocumentDOM() != null &&
  37.              dw.getDocumentDOM().getParseMode() == 'html' && 
  38.              !(dw.getDocumentDOM().getCCSharedSetting_TextOnlyInNonTemplates())
  39.  
  40.   return enabled;
  41. }
  42.  
  43. function commandButtons()
  44. {
  45.    return new Array("PutButtonsOnBottom", "OkButton", MM.BTN_OK, "createAnchorString()", "CancelButton", MM.BTN_Cancel, 
  46.                     "window.close()", "PutButtonOnLeft", MM.BTN_Help, "displayHelp()");
  47. }
  48.  
  49.  
  50. function createAnchorString()
  51. {
  52.   var anchorString =  document.forms[0].anchorname.value;
  53.  
  54.   var errorStr = CheckNewAnchor( anchorString );
  55.   
  56.   if (!errorStr)
  57.   { 
  58.     var curDOM = dw.getDocumentDOM();
  59.     anchorString = dw.doURLEncoding(anchorString);  //URL encode to avoid problem with hi-ascii & double-byte
  60.  
  61.     var idStr = ''
  62.     if (curDOM.getIsXHTMLDocument())
  63.       idStr = ' id="' + anchorString + '"'
  64.  
  65.     dw.showInvisibles();
  66.  
  67.     var htmlStr = "";
  68.     if (dw.getFocus(true) == 'html' || dw.getFocus() == 'textView')
  69.       htmlStr ='<a name="' + anchorString + '"' + idStr + '></a>';
  70.     else
  71.       htmlStr ='<a name="' + anchorString + '"' + idStr + '>';
  72.  
  73.     var curSel = dw.getSelection();  //get selection
  74.     if (curSel && curSel.length>1) //if selection exists
  75.     {
  76.       curDOM.setSelection(curSel[0],curSel[0]);  //put IP prior to selection so inserts before
  77.     }
  78.     curDOM.insertHTML( htmlStr , false);
  79.     window.close();
  80.   }
  81.  
  82.   else
  83.   {
  84.     alert (errorStr);
  85.     document.theform.anchorname.focus();
  86.     document.theform.anchorname.select();
  87.   }
  88. }
  89.